home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
BARNET
/
FREENET
/
BRODIE
/
INTERNET
/
!InternetD
/
h
/
inetd
< prev
next >
Wrap
Text File
|
1995-06-08
|
5KB
|
184 lines
/* inetd.h */
/* To avoid confusion...
* inetdb_... calls are in libsocket together with a safe SWI veneer
* The SWI veneer is now SVC mode call safe (ie. it stacks R14)
*/
#define socketclose close
#define socketioctl ioctl
extern char *socket_errno_to_string(void)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <errno.h>
#include <ctype.h>
#include "sys/errno.h"
#include "netdb.h"
#include "netinet/in.h"
#include "sys/socket.h"
#include "sys/ioctl.h"
#include "sys/byteorder.h"
#include "sys/select.h"
#include "finger.h"
#ifndef UNUSED
#define UNUSED(x) (x)=(x)
#endif
/*---- a callback function for connections to be made ----*/
typedef void (*connection_handler)(int);
/*---- a listening socket (tcp or udp) description ----*/
typedef struct inet_service {
int control_socket;
int type;
int active;
char *name;
int port;
connection_handler connect_handler;
} inet_service;
/*---- flags for indicating the capabilities of a callback, or a
*---- reason for its invocation. All combinations have a value
*---- so now |= operation are required (which then need casting
*---- to stop compiler warnings ----*/
typedef enum {
worker_io_none = 0,
worker_io_read = 1,
worker_io_write = 2,
worker_io_readwrite = 3,
worker_io_except = 4,
worker_io_eread = 5,
worker_io_ewrite = 6,
worker_io_ereadwrite = 7
} worker_io_flags;
/*---- status information for the chargen service ----*/
typedef struct {
int state;
int offset;
} chargen_details;
/*---- status information for the echo service ----*/
typedef struct {
char *buffer;
int size;
int offset;
} echo_details;
/*---- status information for the finger service ----*/
typedef struct {
worker_io_flags state;
FILE *file;
int current_context;
int offset;
} finger_details;
/*---- status information for all services ----*/
typedef union {
chargen_details chargen;
echo_details echo;
finger_details finger;
} service_details;
/*---- function prototype for a backgroud worker callback ----*/
struct inet_handler;
typedef void (*worker_function)(struct inet_handler *, worker_io_flags);
/*---- an object representing an open connection.
*---- an array of these is maintained internally ----*/
typedef struct inet_handler {
int data_socket;
worker_function data_handler;
worker_io_flags flags;
service_details data;
} inet_handler;
/*---- miscellaneous status variables required by the background
*---- routines for buffers etc. ----*/
typedef struct {
struct netwall *netwall;
struct ntalk *ntalk;
struct syslog *syslog;
struct finger finger;
} data_details;
/*---- the system status. Contains fd_set structures which MUST be
*---- copied to another fd_set before passing to select().
*---- Also contains a pointer to the RMA workspace for the pollword
*---- */
typedef struct sys_status {
fd_set listeners;
fd_set workers_readers;
fd_set workers_writers;
fd_set workers_excepts;
int wimp_poll_word;
inet_handler *inets;
inet_service *inetd;
data_details data;
} sys_status;
extern __pure sys_status *sys(void);
extern sys_status *sys_set(sys_status *);
/* kill_socket - takes a pointer to a socket handle
* if the handle isn't -1, it shuts down the socket,
* closes it, and puts -1 in the handle
*/
void kill_socket(int *s);
/*---- background work processor (de)registration ----*/
inet_handler *worker_register(int s, worker_function fn, worker_io_flags);
void worker_deregister(int s);
/* the local interface to the syslog call
* Note that this must not have the #pragma -v1
* declaration around it, as it may contain non-standard
* % specifiers
*/
void syslog(int lev, char *message, ...);
/*---- background connect handlers ----*/
extern void echo_udp(int);
extern void echo_tcp(int);
extern void discard_tcp(int);
extern void discard_udp(int);
extern void daytime_udp(int);
extern void daytime_tcp(int);
extern void ntalk_udp(int);
extern void netwall_udp(int);
extern void biff_udp(int);
extern void syslog_udp(int);
extern void chargen_udp(int);
extern void chargen_tcp(int);
extern void finger_tcp(int);
/*---- background i/o handlers ----*/
extern void discard_data(inet_handler *, worker_io_flags);
extern void echo_data(inet_handler *, worker_io_flags);
extern void chargen_data(inet_handler *, worker_io_flags);
/*---- foreground i/o handlers ----*/
extern void netwall_fg_data(inet_handler *);
extern void syslog_fg_data(inet_handler *);
extern void ntalk_fg_data(inet_handler *);
extern void finger_fg_data(inet_handler *);
/*---- initialisation handlers ----*/
extern int netwall_init(void);
extern int ntalk_init(void);
extern int syslog_init(void);
/*---- useful macro ----*/
#define socket_non_blocking(s) ioctl(s, FIONBIO, 1)
char *socket_errno_to_string(void);